package cn.com.codingce.student.service.impl;

import cn.com.codingce.student.dao.IStudentDao;
import cn.com.codingce.student.dao.impl.StudentDaoImpl;
import cn.com.codingce.student.entity.Student;
import cn.com.codingce.student.service.IStudentService;

import java.util.List;


/*
 * 业务逻辑层  逻辑性的增、删、改(增:查+增，   对dao层进行的组装)
 */
public class StudentServiceImpl implements IStudentService {
	/*
	 * 左边接口右边实现类
	 */
	IStudentDao studentDao = new StudentDaoImpl();
	
	
	/*
	 * 查询全部学生
	 */
	@Override
	public List<Student> queryAllStudents() {
		return studentDao.queryAllStudents();
	}

	/*
	 * 根据学号查询一个人
	 */
	@Override
	public Student queryStudentBySno(int sno) {
		return studentDao.queryStudentBySno(sno);
	}

	/*
	 * 修改学生
	 */
	@Override
	public boolean updateStudentBySno(int sno, Student student) {
		if (studentDao.isExist(sno)) {
			return studentDao.updateStudentBySno(sno, student);
		} else
			return false;
	}

	/*
	 * 删除学生
	 */
	@Override
	public boolean deleteStudentNySno(int sno) {
		if (studentDao.isExist(sno)) {
			return studentDao.deleteStudentBySno(sno);
		} else
			return false;
	}

	/*
	 * 添加学生
	 */
	@Override
	public boolean addStudent(Student student) {
		if (!studentDao.isExist(student.getSno())) {
			studentDao.addStudent(student);
			return true;
		} else {
			System.out.println("此人已存在!");
			return false;
		}
	}

	/*
	 * (non-Javadoc)
	 * @see xyz.reapsun.service.IStudentService#queryStudentByPage(int, int)
	 * 查询当前页面数据集合
	 */
	@Override
	public List<Student> queryStudentByPage(int currentPage, int pageSize) {
		
		return studentDao.queryStudentsByPage(currentPage,pageSize);
	}

	
	/*
	 * 查询数据总条数
	 */
	@Override
	public int getTotalCount() {
		return studentDao.getTotalCount();
	}
}
